/* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements.  See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License.  You may obtain a copy of the License at
*
*     http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/


/*************************************************************************
 *\author: starlove
 *************************************************************************/
#ifndef __CC_PYTHON_IMPORT_O_SPRITEFRAME_IMPL__
#define __CC_PYTHON_IMPORT_O_SPRITEFRAME_IMPL__

#include "python_object_spriteframe.h"

NS_CCPY_BEGIN
	CC_OBJECT_WRAPPER_IMPL(CCSpriteFrame, CPySpriteFrame)
	std::string &__CCSpriteFrameWrapper::g_getTextureFilename()
	{
		return this->m_strTextureFilename;
	}
	
	PYCLASS_INIT_AND_BASE(CPySpriteFrame, CPyCCObject, "CCSpriteFrame", "Python CCSpriteFrame Object");
	PYCLASS_BEGIN_METHOD_DEF(CPySpriteFrame)
	PYCLASS_ADD_METHOD_EX(CPySpriteFrame, initWithTexture			, METH_KEYWORDS|METH_VARARGS)
	PYCLASS_ADD_METHOD_EX(CPySpriteFrame, initWithTextureFilename	, METH_KEYWORDS|METH_VARARGS)
	PYCLASS_END_METHOD_DEF(CPySpriteFrame)
	PYCLASS_BEGIN_GETSET_DEF(CPySpriteFrame)
	
	PYCLASS_ADD_GETSET(CPySpriteFrame, RectInPixels)
    PYCLASS_ADD_GETSET(CPySpriteFrame, Rotated)
    PYCLASS_ADD_GETSET(CPySpriteFrame, Rect)
    PYCLASS_ADD_GETSET(CPySpriteFrame, OffsetInPixels)
    PYCLASS_ADD_GETSET(CPySpriteFrame, OriginalSizeInPixels)
    PYCLASS_ADD_GETSET(CPySpriteFrame, OriginalSize)
    PYCLASS_ADD_GETSET(CPySpriteFrame, Texture)
    PYCLASS_ADD_GETSET(CPySpriteFrame, Offset)
    PYCLASS_ADD_GET(CPySpriteFrame, TextureFilename)

	PYCLASS_END_GETSET_DEF(CPySpriteFrame)
	PYCLASS_IMP_INTERFACE_NEW(CPySpriteFrame)
			
	int CPySpriteFrame::__init__(CPySpriteFrame *pySelf, PyObject *args, PyObject *kwds)
	{
		pySelf->setRaw();
		static char *kwlist[] = {"filename", "texture", "rect", "rotated", "offset", "originalSize", NULL};
		char *file = "";
		PyObject *pytex = NULL;
		PyObject *pyrt = NULL;
		PyObject *pyrotated = NULL;
		PyObject *pyoffset = NULL;
		PyObject *pyorigsize = NULL;

		if(!PyArg_ParseTupleAndKeywords(args,kwds,"|sOOOOO",kwlist, &file, &pytex, &pyrt, &pyrotated, &pyoffset, &pyorigsize))
			return 0;

		if( !PyObject_TypeCheck(pyrt, CPyClassBase::GetTypeObject<CPyRect>()) )
			return 0;

		CPyRect *rt = (CPyRect *)pyrt;
		CPyPoint *offset = NULL;
		CPySize *origsize = NULL;
		if(PyObject_TypeCheck(pyoffset, CPyClassBase::GetTypeObject<CPyPoint>()) && PyObject_TypeCheck(pyorigsize, CPyClassBase::GetTypeObject<CPySize>()))
		{
			offset = (CPyPoint *)pyoffset;
			origsize = (CPySize *)pyorigsize;
		}

		if( (file && strlen(file) >= 0) )
		{
			if(pyrotated != Py_None && offset && origsize)
			{
				CC_METHOD_WRAPPER_SETER_RINT(__CCSpriteFrameWrapper *, CPySpriteFrame,  initWithTextureFilename, file, rt->getCCObject(), pyrotated != Py_False, offset->getCCObject(), origsize->getCCObject());
			}else
				CC_METHOD_WRAPPER_SETER_RINT(__CCSpriteFrameWrapper *, CPySpriteFrame,  initWithTextureFilename, file, rt->getCCObject());
		}else if( (PyObject_TypeCheck(pytex, CPyClassBase::GetTypeObject<CPyTexture2D>())) )
		{
			CPyTexture2D *tex2d = (CPyTexture2D *)pytex;
			if(pyrotated != Py_None && offset && origsize)
			{
				CC_METHOD_WRAPPER_SETER_RINT(__CCSpriteFrameWrapper *, CPySpriteFrame,  initWithTexture, (cocos2d::CCTexture2D *)tex2d->getCCObject(), rt->getCCObject(), pyrotated != Py_False, offset->getCCObject(), origsize->getCCObject());
			}else
				CC_METHOD_WRAPPER_SETER_RINT(__CCSpriteFrameWrapper *, CPySpriteFrame,  initWithTexture, (cocos2d::CCTexture2D *)tex2d->getCCObject(), rt->getCCObject());
		}
		return 0;
	}

	void CPySpriteFrame::__del__(CPySpriteFrame *self)
	{
		self->ob_type->tp_free(self);
	}
	
	PYCLASS_METHOD_KW_IMPL(CPySpriteFrame, initWithTexture)
	{
		static char *kwlist[] = {"filename", "rect", "rotated", "offset", "originalSize", NULL};
		char *file = "";
		PyObject *pyrt = NULL;
		PyObject *pyrotated = NULL;
		PyObject *pyoffset = NULL;
		PyObject *pyorigsize = NULL;

		if(!PyArg_ParseTupleAndKeywords(pyArgs,pyKW,"|sOOOO",kwlist, &file, &pyrt, &pyrotated, &pyoffset, &pyorigsize))
			Py_RETURN_NONE;

		if( !PyObject_TypeCheck(pyrt, CPyClassBase::GetTypeObject<CPyRect>()) )
			Py_RETURN_NONE;

		CPyRect *rt = (CPyRect *)pyrt;
		CPyPoint *offset = NULL;
		CPySize *origsize = NULL;
		if(PyObject_TypeCheck(pyoffset, CPyClassBase::GetTypeObject<CPyPoint>()) && PyObject_TypeCheck(pyorigsize, CPyClassBase::GetTypeObject<CPySize>()))
		{
			offset = (CPyPoint *)pyoffset;
			origsize = (CPySize *)pyorigsize;
		}

		if( (file && strlen(file) >= 0) )
		{
			if(pyrotated != Py_None && offset && origsize)
			{
				CC_METHOD_WRAPPER_SETER(__CCSpriteFrameWrapper *, CPySpriteFrame,  initWithTextureFilename, file, rt->getCCObject(), pyrotated != Py_False, offset->getCCObject(), origsize->getCCObject());
			}else
				CC_METHOD_WRAPPER_SETER(__CCSpriteFrameWrapper *, CPySpriteFrame,  initWithTextureFilename, file, rt->getCCObject());
		}
		Py_RETURN_NONE;
	}

	PYCLASS_METHOD_KW_IMPL(CPySpriteFrame, initWithTextureFilename)
	{
		static char *kwlist[] = {"texture", "rect", "rotated", "offset", "originalSize", NULL};
		PyObject *pytex = NULL;
		PyObject *pyrt = NULL;
		PyObject *pyrotated = NULL;
		PyObject *pyoffset = NULL;
		PyObject *pyorigsize = NULL;

		if(!PyArg_ParseTupleAndKeywords(pyArgs,pyKW,"|OOOOO",kwlist, &pytex, &pyrt, &pyrotated, &pyoffset, &pyorigsize))
			Py_RETURN_NONE;

		if( !PyObject_TypeCheck(pyrt, CPyClassBase::GetTypeObject<CPyRect>()) )
			Py_RETURN_NONE;

		CPyRect *rt = (CPyRect *)pyrt;
		CPyPoint *offset = NULL;
		CPySize *origsize = NULL;
		if(PyObject_TypeCheck(pyoffset, CPyClassBase::GetTypeObject<CPyPoint>()) && PyObject_TypeCheck(pyorigsize, CPyClassBase::GetTypeObject<CPySize>()))
		{
			offset = (CPyPoint *)pyoffset;
			origsize = (CPySize *)pyorigsize;
		}

		if( (PyObject_TypeCheck(pytex, CPyClassBase::GetTypeObject<CPyTexture2D>())) )
		{
			CPyTexture2D *tex2d = (CPyTexture2D *)pytex;
			if(pyrotated != Py_None && offset && origsize)
			{
				CC_METHOD_WRAPPER_SETER(__CCSpriteFrameWrapper *, CPySpriteFrame,  initWithTexture, (cocos2d::CCTexture2D *)tex2d->getCCObject(), rt->getCCObject(), pyrotated != Py_False, offset->getCCObject(), origsize->getCCObject());
			}else
				CC_METHOD_WRAPPER_SETER(__CCSpriteFrameWrapper *, CPySpriteFrame,  initWithTexture, (cocos2d::CCTexture2D *)tex2d->getCCObject(), rt->getCCObject());
		}
		Py_RETURN_NONE;
	}

	PYCLASS_GET_IMPL(CPySpriteFrame, RectInPixels)
	{
		CC_METHOD_WRAPPER_GETER(__CCSpriteFrameWrapper *, CPySpriteFrame,  getRectInPixels, cocos2d::CCRect);
		CPyRect *rt = CPyRect::create(v);
		return (PyObject *)rt;
	}
	
	PYCLASS_SET_IMPL(CPySpriteFrame, RectInPixels)
	{
		if( (PyObject_TypeCheck(pyValue, CPyClassBase::GetTypeObject<CPyRect>())) )
			return 0;
		CPyRect *rt = (CPyRect *)pyValue;
		CC_METHOD_WRAPPER_SETER_RINT(__CCSpriteFrameWrapper *, CPySpriteFrame,  setRectInPixels, rt->getCCObject());
		return 0;
	}

	PYCLASS_GET_IMPL(CPySpriteFrame, Rotated)
	{
		CC_METHOD_WRAPPER_GETER(__CCSpriteFrameWrapper *, CPySpriteFrame,  isRotated, bool);
		Py_RETURN_BOOL(v);
	}
	
	PYCLASS_SET_IMPL(CPySpriteFrame, Rotated)
	{
		CC_METHOD_WRAPPER_SETER_RINT(__CCSpriteFrameWrapper *, CPySpriteFrame,  setRotated, pyValue != Py_False);
		return 0;
	}
	
	PYCLASS_GET_IMPL(CPySpriteFrame, Rect)
	{
		CC_METHOD_WRAPPER_GETER(__CCSpriteFrameWrapper *, CPySpriteFrame,  getRect, cocos2d::CCRect);
		CPyRect *rt = CPyRect::create(v);
		return (PyObject *)rt;
	}
	
	PYCLASS_SET_IMPL(CPySpriteFrame, Rect)
	{
		if( (PyObject_TypeCheck(pyValue, CPyClassBase::GetTypeObject<CPyRect>())) )
			return 0;
		CPyRect *rt = (CPyRect *)pyValue;
		CC_METHOD_WRAPPER_SETER_RINT(__CCSpriteFrameWrapper *, CPySpriteFrame,  setRect, rt->getCCObject());
		return 0;
	}
	
	PYCLASS_GET_IMPL(CPySpriteFrame, OffsetInPixels)
	{
		CC_METHOD_WRAPPER_GETER(__CCSpriteFrameWrapper *, CPySpriteFrame,  getOffsetInPixels, cocos2d::CCPoint);
		CPyPoint *pt = CPyPoint::create(v);
		return (PyObject *)pt;
	}
	
	PYCLASS_SET_IMPL(CPySpriteFrame, OffsetInPixels)
	{
		if( (PyObject_TypeCheck(pyValue, CPyClassBase::GetTypeObject<CPyPoint>())) )
			return 0;
		CPyPoint *pt = (CPyPoint *)pyValue;
		CC_METHOD_WRAPPER_SETER_RINT(__CCSpriteFrameWrapper *, CPySpriteFrame,  setOffsetInPixels, pt->getCCObject());
		return 0;
	}
	
	PYCLASS_GET_IMPL(CPySpriteFrame, OriginalSizeInPixels)
	{
		CC_METHOD_WRAPPER_GETER(__CCSpriteFrameWrapper *, CPySpriteFrame,  getOriginalSizeInPixels, cocos2d::CCSize);
		CPySize *si = CPySize::create(v);
		return (PyObject *)si;
	}
	
	PYCLASS_SET_IMPL(CPySpriteFrame, OriginalSizeInPixels)
	{
		if( (PyObject_TypeCheck(pyValue, CPyClassBase::GetTypeObject<CPySize>())) )
			return 0;
		CPySize *si = (CPySize *)pyValue;
		CC_METHOD_WRAPPER_SETER_RINT(__CCSpriteFrameWrapper *, CPySpriteFrame,  setOriginalSizeInPixels, si->getCCObject());
		return 0;
	}
	
	PYCLASS_GET_IMPL(CPySpriteFrame, OriginalSize)
	{
		CC_METHOD_WRAPPER_GETER(__CCSpriteFrameWrapper *, CPySpriteFrame,  getOriginalSize, cocos2d::CCSize);
		CPySize *si = CPySize::create(v);
		return (PyObject *)si;
	}
	
	PYCLASS_SET_IMPL(CPySpriteFrame, OriginalSize)
	{
		if( (PyObject_TypeCheck(pyValue, CPyClassBase::GetTypeObject<CPySize>())) )
			return 0;
		CPySize *si = (CPySize *)pyValue;
		CC_METHOD_WRAPPER_SETER_RINT(__CCSpriteFrameWrapper *, CPySpriteFrame,  setOriginalSize, si->getCCObject());
		return 0;
	}

	PYCLASS_GET_IMPL(CPySpriteFrame, Texture)
	{
		CC_METHOD_WRAPPER_GETER(__CCSpriteFrameWrapper *, CPySpriteFrame,  getTexture, cocos2d::CCTexture2D *);
		CPyTexture2D *tex = CPyCCObject::create<CPyTexture2D>(v);
		return (PyObject *)tex;
	}
	
	PYCLASS_SET_IMPL(CPySpriteFrame, Texture)
	{
		if( (PyObject_TypeCheck(pyValue, CPyClassBase::GetTypeObject<CPyTexture2D>())) )
			return 0;
		CPyTexture2D *tex = (CPyTexture2D *)pyValue;
		CC_METHOD_WRAPPER_SETER_RINT(__CCSpriteFrameWrapper *, CPySpriteFrame,  setTexture, (cocos2d::CCTexture2D *)tex->getCCObject());
		return 0;
	}

	PYCLASS_GET_IMPL(CPySpriteFrame, Offset)
	{
		CC_METHOD_WRAPPER_GETER(__CCSpriteFrameWrapper *, CPySpriteFrame,  getOffset, cocos2d::CCPoint);
		CPyPoint *pt = CPyPoint::create(v);
		return (PyObject *)pt;
	}
	
	PYCLASS_SET_IMPL(CPySpriteFrame, Offset)
	{
		if( (PyObject_TypeCheck(pyValue, CPyClassBase::GetTypeObject<CPyPoint>())) )
			return 0;
		CPyPoint *pt = (CPyPoint *)pyValue;
		CC_METHOD_WRAPPER_SETER_RINT(__CCSpriteFrameWrapper *, CPySpriteFrame,  setOffset, pt->getCCObject());
		return 0;
	}
	
	PYCLASS_GET_IMPL(CPySpriteFrame, TextureFilename)
	{
		CC_METHOD_WRAPPER_GETER(__CCSpriteFrameWrapper *, CPySpriteFrame,  g_getTextureFilename, std::string);
		return Py_BuildValue("s", v.c_str());
	}

NS_CCPY_END

#endif